<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<form [formGroup]="ticketForm" (ngSubmit)="onSubmit()" gioFormFocusInvalid class="user-support-new-ticket">
  <h2><gio-go-back-button [routerLink]="'../'"></gio-go-back-button> New Ticket</h2>
  <h4>Create a new support ticket</h4>

  <mat-card>
    <mat-card-content>
      <mat-form-field class="user-support-new-ticket__form-field">
        <mat-label>API</mat-label>
        <mat-select formControlName="api" aria-label="API" data-testid="api">
          <mat-option></mat-option>
          <mat-option *ngFor="let api of apis" [value]="api.id">{{ api.name }} ({{ api.apiVersion }})</mat-option>
        </mat-select>
      </mat-form-field>

      <mat-form-field class="user-support-new-ticket__form-field">
        <mat-label>Application</mat-label>
        <mat-select formControlName="application" aria-label="Application" data-testid="application">
          <mat-option></mat-option>
          <mat-option *ngFor="let application of applications" [value]="application.id"
            >{{ application.name }} ({{ application.owner.displayName }})</mat-option
          >
        </mat-select>
      </mat-form-field>

      <mat-form-field class="user-support-new-ticket__form-field">
        <mat-label>Subject</mat-label>
        <input matInput formControlName="subject" required data-testid="subject" />
        <mat-error *ngIf="ticketForm.get('subject').errors?.required">This field is required.</mat-error>
      </mat-form-field>

      <mat-form-field class="user-support-new-ticket__form-field">
        <mat-label>Content</mat-label>
        <textarea
          matInput
          formControlName="content"
          class="user-support-new-ticket__form-field__content-field"
          required
          data-testid="content"
        >
        </textarea>
        <mat-error *ngIf="ticketForm.get('content').errors?.required">This field is required.</mat-error>
      </mat-form-field>

      <gio-form-slide-toggle>
        Receive a copy of this ticket by email
        <mat-slide-toggle
          gioFormSlideToggle
          formControlName="copyToSender"
          aria-label="Copy to sender"
          data-testid="copyToSender"
        ></mat-slide-toggle>
      </gio-form-slide-toggle>
    </mat-card-content>
  </mat-card>

  <gio-save-bar [creationMode]="true" [form]="ticketForm"> </gio-save-bar>
</form>
